﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace WebSysCore
{
    public class XSubjectList
    {
        private List<XSubject> lst;
        public XSubject[] xSubjectList;
        public XSubjectList()
        {
            lst = new List<XSubject>();
        }
        public void Add(XSubject x)
        {
            lst.Add(x);
            xSubjectList = lst.ToArray();
        }

        public static void ToXML(XSubjectList lst, string filePath)
        {
            XmlSerializer ser = new XmlSerializer(typeof(XSubjectList));
            FileStream fs = new FileStream(filePath, FileMode.Create);
            ser.Serialize(fs, lst);
            fs.Close();
        }
        public static XSubjectList FromXML(string filePath)
        {
            XmlSerializer ser = new XmlSerializer(typeof(XSubjectList));
            try
            {
                FileStream fs = new FileStream(filePath, FileMode.Open);
                XSubjectList lst = (XSubjectList)ser.Deserialize(fs);
                fs.Close();
                return lst;
            }
            catch
            {
                throw new Exception("File does not exist");
            }
        }
    }
}
